package com.darchrow.springcloud.service.impl;

import cn.hutool.core.lang.UUID;
import com.darchrow.springcloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;

/**
 * 发送消息（source、channel、binder）
 *
 * @author mdl
 * @version 1.0
 * @date 2020/10/12 14:09
 */
@EnableBinding(Source.class)
@Slf4j
public class MessageProviderImpl implements IMessageProvider {

    /**
     * 这里的名字必须为output, 跟yml里一致
     */
    @Resource
    private MessageChannel output;

    @Override
    public void send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        log.info("*******serial: " + serial);
    }
}
